<?php

/**
 * 标签管理
 * File Name：TagsController.php
 * File Encoding：UTF-8
 * File New Time：2014-9-15 15:00:13
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class TagsController extends AdminBase {

    //标签列表
    public function actionIndex() {
        //搜索
        if (IS_POST) {
            foreach ($_POST as $k => $v) {
                if ($v == '') {
                    unset($_POST[$k]);
                }
            }
            $this->redirect(self::U('index', $_POST));
            exit;
        }
        $model = TagsModel::model();
        $where = array(
            'order' => 'usetimes desc,tagid desc'
        );
        $keyword = trim(Yii::app()->request->getParam('keyword'));
        if (!empty($keyword)) {
            $this->assign('keyword', $keyword);
            $where['tag'] = array('LIKE', "%{$keyword}%");
        }
        $this->basePage($model, $where, 20);
        $this->render();
    }

    //删除
    public function actionDelete() {
        $tagid = (int) Yii::app()->request->getParam('tagid');
        $model = TagsModel::model();
        $data = $model->findByPk($tagid);
        if (empty($data)) {
            $this->error('该标签不存在！');
        }
    }

}
